package 面向对象初级.封装.封装的实现;

public class Person {
    //私有化person的类
    private String name;
    private int age;
    private boolean marry;

    //得到私有化的属性值
    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public boolean getMarry() {
        return marry;
    }

    //向私有化的属性来进行赋值
    public void setName(String newName) {
        name = newName;
    }

    public void setAge(int newAge) {
        if (newAge >= 0 && newAge <= 130) {
            age = newAge;
        } else {
            age = 18;
            System.out.println("不好意思，输入失败");
        }

    }

    public void setMarry(boolean newMarry) {
        marry = newMarry;
    }

    //输出Person对象信息的方法
    private void print() {
        System.out.println("姓名为" + name + "年龄为" + age + "是否结婚" + marry);
    }
    //转换一下来进行调用
    public void toInfo(){
        print();
    }
}
